package com.czh.springboot04.service.serviceimpl;

import com.czh.springboot04.entity.User;
import com.czh.springboot04.mapper.UserMapper;
import com.czh.springboot04.service.UserService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;

    @Override
    public User findByUsername(String username) {
        return userMapper.findUserByUsername(username);
    }

    @Override
    public User findByUsernameAndPassword(User user) {
        User u1 = userMapper.findByUsernameAndPassword(user);
        if (u1 != null) {
            return u1;
        }
        return null;
    }

    @Override
    public PageInfo<User> selectAll(int pageNum, int pageSize, User user) {
        PageHelper.startPage(pageNum,pageSize);
        List<User> users = userMapper.selectAll(user);
        return new PageInfo<>(users);
    }

    @Override
    public int addUser(User user) {
        return userMapper.addUser(user);
    }

    @Override
    public int deleteUser(int id) {
        return userMapper.deleteUser(id);
    }

    @Override
    public int deleteUsers(int[] ids) {
        return 0;
    }

    @Override
    public int updateU(User user) {
        return userMapper.updateU(user);
    }
    @Override
    public User selectById(int id) {
        return userMapper.selectById(id);
    }

    @Override
    public int getUserCount() {
        return userMapper.getUserCount();
    }
}